<template>
  <div class="page">
    <div class="tab-list">
      <div
        class="tab"
        v-for="(item, index) in tabList"
        :class="{ active: currentTab === index }"
        :key="index"
        @click="toggleTab(index)"
      >
        {{ item.label }}
        <div class="active-line" v-if="currentTab === index"></div>
      </div>
    </div>

    <div class="vip-list">
      <div class="vip-item">
        <div class="vip-info">
          <div class="vip-name">{{tabList[currentTab].label}}</div>
          <div class="price">
            <span class="char">￥</span>
            {{vipInfo.price || 0}}
          </div>
          <div class="date" v-if="userInfo.vipEnd">到期时间：{{userInfo.vipEnd}}</div>
        </div>
        <div class="buy-btn">立即开通</div>
      </div>
    </div>

    <div class="desc-wrapper">
      <div class="title">{{tabList[currentTab].label}}权益说明</div>
      <div class="content" v-html="vipInfo.intro"></div>
    </div>
  </div>
</template>

<script>
import { getVipList, openVip } from '@/api/common.js'
import { mapGetters } from 'vuex'
export default {
  name: "vip",

  data() {
    return {
      tabList: [
        { label: "月度会员", value: 1 },
        { label: "季度会员", value: 2 },
        { label: "年费会员", value: 3 },
      ],
      currentTab: 0,
      content: '',
      vipInfo: {}
    };
  },
  created(){
    this.getVipList()
  },
  computed: {
			...mapGetters(['userInfo'])
		},
  methods: {
    toggleTab(index) {
      this.currentTab = index;
      this.vipInfo = {}
      this.getVipList()
    },
    getVipList(){
				getVipList({vip_type: this.tabList[this.currentTab].value}).then(res => {
					this.vipInfo = res.result[0]
				})
			},
  },
};
</script>

<style lang="scss" scoped>
.page {
  width: 100%;
}

.tab-list {
  display: flex;
  width: 100%;

  border-bottom: 1px solid #f1f1f1;

  .tab {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    font-weight: normal;
    font-size: 20px;
    color: #333333;
    color: #333333;
    cursor: pointer;
    padding-top: 30px;
    padding-bottom: 20px;
  }

  .active {
    font-weight: bold;
    color: #fe5a13;
  }

  .active-line {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 6px;
    background: #fe5a13;
    border-radius: 3px 3px 3px 3px;
  }
}

.vip-list {
  display: flex;
  flex-wrap: wrap;
  padding: 40px 30px;

  .vip-item {
    display: flex;
    height: 183px;
    background: #fffaf7;
    border-radius: 16px 16px 16px 16px;
    border: 1px solid #ff8652;

    .vip-info {
      display: flex;
      flex-direction: column;
      justify-content: center;
      padding: 30px;
      flex: 1;
      min-width: 180px;

      .vip-name {
        font-weight: normal;
        font-size: 20px;
        color: #333333;
      }

      .price {
        display: flex;
        font-weight: bold;
        font-size: 40px;
        color: #fe5a13;
        padding: 12px 0;

        .char {
          position: relative;
          top: -3px;
          font-weight: bold;
          font-size: 20px;
          align-self: flex-end;
        }
      }

      .date {
        font-weight: normal;
        font-size: 16px;
        color: #808080;
      }
    }
  }

  .buy-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 68px;
    height: 183px;
    writing-mode: vertical-rl;
    background: #ff783e;
    border-radius: 0px 16px 16px 0px;
    border: 1px solid #ff8652;
    font-weight: bold;
    font-size: 18px;
    color: #ffffff;
    letter-spacing: 10px;
    cursor: pointer;
  }
}

.desc-wrapper{
  margin: 50px 30px;
background: #F7F7F7;
border-radius: 4px 4px 4px 4px;

.title{
  font-weight: 400;
font-size: 20px;
color: #000000;
padding: 20px;
}

.content{
  padding: 0 20px 1px;
}
}
</style>
